﻿@{
    Layout = null;
}

<!DOCTYPE html>
<html>
<head>
    <link rel="shortcut icon" href="favicon.ico">
    <link rel="icon" type="image/gif" href="~/img/animated_favicon1.gif">
    <link href="~/UILibs/easyui/themes/default/easyui.css" rel="stylesheet" />
    <link href="~/UILibs/easyui/themes/icon.css" rel="stylesheet" />
    <link href="~/Css/css.css" rel="stylesheet" />

    <script src="~/Scripts/jquery-1.7.1.min.js"></script>
    <script src="~/Scripts/jquery.jqprint-0.3.js"></script>
    <script src="~/UILibs/easyui/jquery.easyui.min.js"></script>

    <script src="~/UILibs/easyui/locale/easyui-lang-zh_CN.js"></script>
    <script src="~/Scripts/jquery.unobtrusive-ajax.min.js"></script>
    <script src="~/Scripts/jquery.validate.min.js"></script>
    <script src="~/Scripts/jquery.validate.unobtrusive.min.js"></script>
    <script src="~/Scripts/datagrid-detailview.js"></script>
    <title></title>
    <style type="text/css">
        .subtotal {
            font-weight: bold;
            color: black;
            /*//background-color: dodgerblue;*/
            height: 200px;
            width: 200px;
            font-size: 20px;
        }

        .subtotal2 {
            font-weight: bold;
            color: black;
            width: 6%;
            margin-top: 10px;
            background-color: orange;
            font-size: 20px;
        }
        /*合计单元格样式*/
    </style>
    <script type="text/javascript">
        $(function () {
            $.ajax({
                url: pageConfig.getActionAll,
                dataType: "JSON",
                type: "GET",
                success: function (data) {
                    //alert(data.rate);
                    $("#txtNum").val(data.lossNum);
                    $("#txtMoney").val(data.lossMoney + "元");
                    $("#txtRate").val(data.rate);
                }
            });
        });
    </script>

    <script type="text/javascript">
        $(function () {
            $('#shopName').combobox({
                valueField: "StoreID", //Value字段 
                textField: "StoreName", //Text字段                 
                url: "/Loss/GetStore", //数据源 
            });

            $("#data").datagrid({
                fit: true,
                title: '商品亏损统计分析',
                striped: true,
                rownumbers: true,
                showFooter: true,
                columns:
                    [[
                            //x.lossID, x.lossNumber, x.waresCode, x.waresName, x.waresPrice, x.operateTime,x.storeid                        
                            { field: 'waresCode', title: '商品编号', width: 160, halign: 'center', align: 'center' },
                            { field: 'waresName', title: '商品名称', width: 160, halign: 'center', align: 'center' },
                            { field: 'waresPrice', title: '商品进价', width: 150, halign: 'center', align: 'center' },
                            { field: 'lossNumber', title: '相差数量', width: 180, halign: 'center', align: 'center' },
                            { field: 'waresAllPrice', title: '盈亏金额', width: 180, halign: 'center', align: 'center' },
                    ]],
                singleSelect: true,
                loadMsg: '正在加载数据,请耐心等待.......',
                url: pageConfig.getAction,
                queryParams: {
                    date1: $('#txtDate1').val(),
                    date2: $('#txtDate2').val(),
                    storeid: $("#shopName").combobox('getValue'),
                    waresName: $("#waresName").val(),
                },
                pagination: true,
                pageSize: 25,
                pageList: [25, 30, 35],
                //onLoadSuccess: compute,//加载完毕后执行计算
                sortName: 'lossID',
                sortOrder: 'asc',
                toolbar: '#tool',

            });

            $('#data').datagrid({

                view: detailview,
                detailFormatter: function (index, row) {
                    return '<div style="padding:12px"><table class="ddv"></table></div>';
                },
                onExpandRow: function (index, row) {
                    var ddv = $(this).datagrid('getRowDetail', index).find('table.ddv');
                    ddv.datagrid({
                        url: '/Loss/GetDetailByID',
                        fitColumns: true,
                        singleSelect: true,
                        rownumbers: true,
                        loadMsg: '',
                        height: 'auto',
                        columns: [[
                           { field: 'lossType', title: '类型', width: 100, halign: 'center', align: 'center' },
                           { field: 'lossNumber', title: '数量', width: 100, color: 'red', halign: 'center', align: 'center' },
                        ]],
                        onResize: function () {
                            $('#data').datagrid('fixDetailRowHeight', index);
                        },
                        queryParams: {
                            waresCode: row.waresCode,
                            date1: $('#txtDate1').val(),
                            date2: $('#txtDate2').val(),
                            storeid: $("#shopName").combobox('getValue'),
                        }
                    });
                    $('#data').datagrid('fixDetailRowHeight', index);
                }
            });
        });

        //function compute() {//计算函数
        //    var rows = $('#data').datagrid('getRows')//获取当前的数据行
        //    var lossNumber = 0//计算listprice的总和
        //        , waresAllPrice = 0;//统计waresAllPrice的总和
        //    for (var i = 0; i < rows.length; i++) {
        //        lossNumber =accAdd( lossNumber , rows[i]['lossNumber']);
        //        // waresAllPrice += parseFloat(rows[i]['waresAllPrice']);
        //        waresAllPrice =accAdd(waresAllPrice, parseFloat(rows[i]['waresAllPrice']));
        //    }
        //    alert(lossNumber);
        //    $("#txtNum").val(lossNumber);
        //    $("#txtMoney").val(waresAllPrice + "元");
        //}

        //function accAdd(arg1, arg2) {
        //    var r1, r2, m;
        //    try {
        //        r1 = arg1.toString().split(".")[1].length
        //    } catch (e) {
        //        r1 = 0
        //    } try {
        //        r2 = arg2.toString().split(".")[1].length
        //    } catch (e) { r2 = 0 } m = Math.pow(10, Math.max(r1, r2))
        //    return (arg1 * m + arg2 * m) / m
        //}

        var pageConfig = {
            getAction: '@Url.Action("GetLossBySql")',
            getActionAll: '@Url.Action("GetAllBySql")',
            getShopName: '@Url.Action("GetShopName")',
        };

        function searchData() {
            $.ajax({
                //查询加载总金额              
                url: "/Loss/GetAllBySql?date1=" + $('#txtDate1').val() + '&date2=' + $('#txtDate2').val() + '&waresName=' + $('#waresName').val() + '&storeid=' + $("#shopName").combobox('getValue'),
                queryParams: {
                    date1: $('#txtDate1').val(),
                    date2: $('#txtDate2').val(),
                    storeid: $("#shopName").combobox('getValue'),
                    waresName: $("#waresName").val(),
                },
                dataType: "JSON",
                type: "GET",
                success: function (data) {
                    //alert(data.rate);
                    $("#txtNum").val(data.lossNum);
                    $("#txtMoney").val(data.lossMoney + "元");
                    $("#txtRate").val(data.rate);
                }
            });
            //alert($("#shopName").combobox('getValue')); //获取到的是  id getText 应该是 获取到的name
            var start = $("#txtDate1").datebox('getValue');
            var end = $("#txtDate2").datebox('getValue');
            if (txtDate1.value > txtDate2.value) {
                alert("开始日期不能大于结束日期！");
                $("#txtDate1").textbox('setValue');//清空文本框的值
                $("#txtDate1").textbox('clear');
                $("#txtDate2").textbox('setValue');
                $("#txtDate2").textbox('clear');
                txtDate1.focus();
                txtDate2.focus();
                return false;
            }
            $("#data").datagrid('load', {

                waresName: $("#waresName").val(),
                date1: $('#txtDate1').val(),
                date2: $('#txtDate2').val(),
                storeid: $("#shopName").combobox('getValue'),
            });

        }
    </script>
</head>
<body class="easyui-layout" style="width: 100%; height: 100%">
    <div data-options="region:'center'" id="dataPrint">

        <table id="data" style="height: 50px"></table>
        <table id="data1" hidden="hidden" style="height: 50px"></table>
    </div>

    <div id="tool" style="padding: 30px;">
        <form id="formid" method='post' action='/OrderStatistic/Excel'>
        </form>
        <div>
            商品名称：
                    <input id="waresName" type="text" onchange="searchData()" />
            &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp 
                 店铺名称：
                 <input id="shopName" class="easyui-combobox" name="shopName" />
            &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp 
               日期：<input id="txtDate1" type="text" class="easyui-datebox" />
            -- 
                <input id="txtDate2" type="text" class="easyui-datebox" onchange="searchData()" />
            &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp 
                <a class="easyui-linkbutton" iconcls="icon-search" onclick="searchData()">查询</a>

            <div style="margin-top: 20px;">
                <span style="font-size: 18px; color: red">&nbsp&nbsp &nbsp&nbsp&nbsp   &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp   注意:默认显示为今天的盘库统计，负数表示丢失亏损量</span>
                @*  <br />*@
                &nbsp&nbsp&nbsp  &nbsp&nbsp&nbsp  &nbsp&nbsp&nbsp  &nbsp&nbsp&nbsp<span class="subtotal" style="">相差数量为：</span>
                <input id="txtNum" type="text" class="subtotal2" />
                &nbsp&nbsp&nbsp<span class="subtotal">盈亏金额为：</span>
                <input id="txtMoney" type="text" class="subtotal2" />
                &nbsp&nbsp&nbsp<span class="subtotal">亏损率为：</span>
                <input id="txtRate" type="text" class="subtotal2" />
            </div>

        </div>

    </div>
    <style>
        #dataPrint.datagrid-btable tr {
            height: 50px;
        }
    </style>


</body>

</html>

